﻿using System.Collections.Specialized;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;

namespace Flare
{
    public partial class Style
    {
        void CleanButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            try
            {
                if (((sender as Button).TemplatedParent as ListBox).Items.Count > 1)
                {
                    ((sender as Button).TemplatedParent as ListBox).SelectedIndex = -1;
                }
            }
            catch { }

        }

        void MenuCollectionChanged(object sender, RoutedEventArgs e)
        {
            CollectionView myCollectionView = (CollectionView)CollectionViewSource.GetDefaultView((sender as ListBox).Items);
            ((INotifyCollectionChanged)myCollectionView).CollectionChanged += (se, ee) =>
            {
                (sender as ListBox).SelectedIndex = ((sender as ListBox).Items.Count == 1) ? 0 : -1;
            };
        }
    }
}